﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common.Logging;
using WuDada.Core.Post;
using WuDada.Core.Post.Service;
using WuDada.Core.Post.Domain;
using System.Text;

public partial class UserControl_ActLeft : System.Web.UI.UserControl
{
    private ILog m_Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    private PostFactory m_PostFactory;
    private IPostService m_PostService;

    //近期活動NodeId=6
    private int m_NodeId = 6;
    //講座介紹NodeId=11
    private int m_NodeId2 = 11;

    protected void Page_Load(object sender, EventArgs e)
    {
        m_PostFactory = new PostFactory();
        m_PostService = m_PostFactory.GetPostService();

        if (!IsPostBack)
        {
            GetLeftMenu1List();
            GetLeftMenu2List();
        }
    }

    private void GetLeftMenu2List()
    {
        string sortField = "SortNo";
        bool sortDesc = false;

        IList<PostVO> menuList = m_PostService.GetPostListByNodeId(m_NodeId2, true, sortField, sortDesc);        
        if (menuList != null && menuList.Count > 0)
        {
            StringBuilder sb = new StringBuilder();
            int lastIndex = (menuList.Count - 1);

            for (int i = 0; i < menuList.Count; i++)
            {
                if (i == (lastIndex)) //最後一筆不加 <br />
                {
                    sb.Append(string.Format("<a href='act2.aspx?id={0}' class='leftbtn-s'>{1}</a>"
                        , menuList[i].PostId, menuList[i].Title));
                }
                else
                {
                    sb.Append(string.Format("<a href='act2.aspx?id={0}' class='leftbtn-s'>{1}<br /></a>"
                        , menuList[i].PostId, menuList[i].Title));
                }
            }

            ltlLeftMenu2.Text = sb.ToString();
        }
    }

    private void GetLeftMenu1List()
    {
        string sortField = "SortNo";
        bool sortDesc = false;

        IList<NodeVO> menuList = m_PostService.GetNodeListByParentId(m_NodeId, sortField, sortDesc);
        if (menuList != null && menuList.Count > 0)
        {
            StringBuilder sb = new StringBuilder();
            int lastIndex = (menuList.Count - 1);

            for (int i = 0; i < menuList.Count; i++)
            {
                if (i == (lastIndex)) //最後一筆不加 <br />
                {
                    sb.Append(string.Format("<a href='act-all.aspx?nodeId={0}' class='leftbtn-s'>{1}</a>"
                        , menuList[i].NodeId, menuList[i].Name));
                }
                else
                {
                    sb.Append(string.Format("<a href='act-all.aspx?nodeId={0}' class='leftbtn-s'>{1}<br /></a>"
                        , menuList[i].NodeId, menuList[i].Name));
                }
            }

            ltlLeftMenu1.Text = sb.ToString();
        }
    }
}